<?php
include('./library/connection.php');
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
// $email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
// $address = $_REQUEST['address'];
$select = "select * from users where username='$username'";
$result = $mysqli->query($select);
// var_dump($result);
if ($result->num_rows > 0) {
    echo "<script>alert('用户名已存在')</script>";
    echo "<script>location.href='../src/html/reg.html'</script>";
    $mysqli->close();
    die();
}

$insert = "insert into users (username,password,phone) values ('$username','$password','$phone')";

$result2 = $mysqli->query($insert);
if ($result2) {
    $mysqli->close();
    echo "<script>alert('注册成功')</script>";
    echo "<script>location.href='../src/html/login.html'</script>";
} else {
    echo '出现未知错误';
}
